﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class TestDAL
    {
        private ConnectionConfig connection = null;
        public SqlSugarClient db = null;
        public TestDAL()
        {
            string SqlIP = "192.168.2.5";
            string database = "MESDB";
            string uid = "sa";
            string pwd = "8ik,9ol.";
            connection = new ConnectionConfig()
            {
                ConnectionString = "server='" + SqlIP + "';initial catalog='" + database + "';uid='" + uid + "';pwd='" + pwd + "'",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            };
            db = new SqlSugarClient(connection);
        }
        public bool InsetTestRecord(Model.t_YF_TestRecord model)
        {
            return db.Insertable(model).ExecuteCommand() == 1;
        }
        public int GetCount(string mocode)
        {
            return db.Queryable<Model.t_YF_TestRecord>().Where(o => o.mocode == mocode&&o.result=="OK").GroupBy(o=>o.sn).Select(o=>o.sn).Count();
        }
    }
}
